From 63277e97d8becd2a253e1f76b528950a92ccf2bb Mon Sep 17 00:00:00 2001 From: robertlipe Date: Wed, 23 Oct 2013 01:49:39 +0000 Subject: [PATCH] Take another run at NMN4. --- gpsbabel/nmn4.cc | 67 ++++++++++++++++++++++++------------------------ 1 file changed, 33 insertions(+), 34 deletions(-) diff --git a/gpsbabel/nmn4.cc b/gpsbabel/nmn4.cc index 1aac5346d..4e039fac1 100644 --- a/gpsbabel/nmn4.cc +++ b/gpsbabel/nmn4.cc @@ -50,7 +50,7 @@ arglist_t nmn4_args[] = { /* helpers */ static char* -nmn4_concat(char* arg0, ...) +nmn4_concat(const char* arg0, ...) { va_list args; char* src, *res; @@ -70,7 +70,7 @@ nmn4_concat(char* arg0, ...) res = xstrappend(res, c); } } - xfree(src); +// xfree(src); src = va_arg(args, char*); } va_end(args); @@ -95,11 +95,12 @@ static void nmn4_read_data(void) { char* buff; - char* str, *c; + char* str; + QString c; int column; int line = 0; - char* zip1, *zip2, *city, *street, *number; + QString zip1, zip2, city, street, number; route_head* route; waypoint* wpt; @@ -118,7 +119,7 @@ nmn4_read_data(void) nmn4_check_line(buff); /* for a quiet compiler */ - zip1 = zip2 = city = street = number = NULL; + zip1 = zip2 = city = street = number = QString(); wpt = waypt_new(); @@ -138,42 +139,32 @@ nmn4_read_data(void) break; case 4: /* ZIP Code */ - if (*c != '-') { - zip1 = xstrdup(c); - } else { - zip1 = xstrdup(""); + if (c[0] != '-') { + zip1 = c; } break; case 5: /* City */ - if (*c != '-') { - city = xstrdup(c); - } else { - city = xstrdup(""); + if (c[0] != '-') { + city = c; } break; case 6: /* ZIP Code -2- */ - if (*c != '-') { - zip2 = xstrdup(c); - } else { - zip2 = xstrdup(""); + if (c[0] != '-') { + zip2 = c; } break; case 7: /* Street */ - if (*c != '-') { - street = xstrdup(c); - } else { - street = xstrdup(""); + if (c[0] != '-') { + street = c; } break; case 8: /* Number */ - if (*c != '-') { - number = xstrdup(c); - } else { - number = xstrdup(""); + if (c[0] != '-') { + number = c; } /* @@ -185,32 +176,40 @@ nmn4_read_data(void) Instead we construct a description from that. */ - if (strcmp(zip1, zip2) == 0) { - *zip2 = '\0'; + if (zip1 == zip2) { + zip2 = QString(); } - if (*city != '\0') { + if (!city.isEmpty()) { /* if any field following city has a value, add a comma to city */ - if ((*street != '\0') || (*number != '\0') || (*zip2 != '\0')) { - city = xstrappend(city, ","); + if (!street.isEmpty() || !number.isEmpty() || !zip2.isEmpty()) { + city += ","; } } /* concats all fields to one string and release */ - wpt->description = nmn4_concat(zip1, city, street, number, zip2, NULL); +#if NEW_STRINGS + wpt->description = zip1.trimmed() + " " + + city.trimmed() + " " + + street.trimmed() + " " + + number.trimmed() + " " + + zip2.trimmed(); +#else + wpt->description = nmn4_concat(zip1.toLatin1().data(), city.toLatin1().data(), street.toLatin1().data(), number.toLatin1().data(), zip2.toLatin1().data(), NULL); +#endif break; case 11: /* longitude */ - sscanf(c, "%lf", &wpt->longitude); + wpt->longitude = c.toDouble(); break; case 12: /* latitude */ - sscanf(c, "%lf", &wpt->latitude); + wpt->latitude = c.toDouble(); break; } - c = csv_lineparse(NULL, "|", "", column++); + c = QString::fromLatin1(csv_lineparse(NULL, "|", "", column++)); } route_add_wpt(route, wpt); } -- 2.30.2